﻿using Entity;
using IRealize;
using Microsoft.AspNetCore.Mvc;
using Realize;
using System.Threading.Tasks;

namespace WebApplication9.Controllers.Salary_Disbur_Manag
{
    public class SDM_sctController : Controller
    {
        private readonly ILogger<SDM_sctController> _logger;
        private readonly IConfiguration configuration;

        public SDM_sctController(ILogger<SDM_sctController> logger, IConfiguration configuration)
        {
            this._logger = logger;
            this.configuration = configuration;
        }
        public IActionResult Index()
        {
            return View();
        }
        public async Task<IActionResult> Server(string bh, string Name, DateTime datak, DateTime dataj)
        {
            ViewBag.bh = bh;
            ViewBag.Name = Name;
            ViewBag.Datak = datak;
            ViewBag.Dataj = dataj;
            return View();
        }
        public async Task<IActionResult> Server_SGD(string ss_id,string sg_id)
        {
            ViewBag.ss_id = ss_id;
            ViewBag.sg_id = sg_id;
            return View();
        }
        public async Task<IActionResult> Index2(string bh, string Name, DateTime datak, DateTime dataj, int i, int p)
        {
            ISG sg = new SG();
            List<Salary_Grant> zhi = await sg.Server3(configuration["SqlServer"]);
            List<Salary_Grant> zhi3 = zhi.ToList();
            if (bh != null && bh != "" && bh != "undefined")
            {
                zhi3 = zhi3.Where(e => e.salary_standard_id.Contains(bh)).ToList();
            }
            if (Name != null && Name != "" && Name != "undefined")
            {
                zhi3 = zhi3.Where(e => e.first_kind_name.Contains(Name) || e.second_kind_name.Contains(Name) || e.third_kind_name.Contains(Name)).ToList();
            }
            if (datak != DateTime.MinValue && dataj != DateTime.MinValue)
            {
                zhi3 = zhi3.Where(e => e.regist_time >= datak).ToList();
                zhi3 = zhi3.Where(e => e.regist_time <= dataj).ToList();
            }
            List<Salary_Grant> zhi2 = zhi3.Skip((i - 1) * p).Take(p).ToList();
            PagedViewModel<Salary_Grant> cc = new PagedViewModel<Salary_Grant>() { itemas = zhi2, total = zhi3.Count };
            return Ok(new
            {
                list = cc
            });
        }
        public class PViewModel 
        {
            public List<Salary_Grant_Details> List_sgd { get; set; }
            public Salary_Grant class_sg { get; set; }
        }
        public async Task<IActionResult> Index3(string ss_id,string sg_id) 
        {
            ISGD sgd = new SGD();
            ISG sg = new SG();
            List<Salary_Grant_Details> list = await sgd.Server(sg_id,configuration["SqlServer"]);
            List<Salary_Grant> list2 = await sg.Server2(sg_id,configuration["SqlServer"]);
            PViewModel pView = new PViewModel() {List_sgd = list, class_sg = list2[0] };

            return Ok(new 
            {
                zhi = pView
            });
        }
        public async Task<IActionResult> Index4(string h_id)
        {
            IHF hf = new HF();
            ISSD ssd = new SSD();
            List<Human_File> list = await hf.Server3(h_id, configuration["SqlServer"]);
            List<Salary_Standard_Details> list2 = await ssd.Server3(list[0].salary_standard_id, configuration["SqlServer"]);

            return Ok(new
            {
                zhi = list2
            });
        }
    }
}
